From abc5e177bb7e22ea4545ab4c41a078c7e864a61e Mon Sep 17 00:00:00 2001 From: oliskoli Date: Mon, 26 Mar 2007 22:18:53 +0000 Subject: [PATCH] Add functions waypt_speed() and waypt_time(). waypt_speed calculates the speed between two points (in meters per second). waypt_time returns the creation_time of a waypoint including microseconds in fractional portion. --- defs.h | 2 ++ waypt.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/defs.h b/defs.h index 28609b2b4..0eb901d9e 100644 --- a/defs.h +++ b/defs.h @@ -662,6 +662,8 @@ void waypt_init(void); void route_init(void); void waypt_disp(const waypoint *); void waypt_status_disp(int total_ct, int myct); +double waypt_time(const waypoint *wpt); +double waypt_speed(const waypoint *A, const waypoint *B); NORETURN fatal(const char *, ...) PRINTFLIKE(1, 2); void is_fatal(const int condition, const char *, ...) PRINTFLIKE(2, 3); diff --git a/waypt.c b/waypt.c index 41ce3d3d3..bc076ff26 100644 --- a/waypt.c +++ b/waypt.c @@ -22,6 +22,7 @@ #include #include "defs.h" #include "cet_util.h" +#include "grtcirc.h" queue waypt_head; static unsigned int waypt_ct; @@ -444,3 +445,39 @@ waypt_add_url(waypoint *wpt, char *link, char *url_link_text) } } } + +/* + * returns full creation_time with parts of seconds in fractional portion + */ + +double +waypt_time(const waypoint *wpt) +{ + if (wpt->creation_time <= 0) + return (double) 0; + else + return ((double)wpt->creation_time + ((double)wpt->microseconds / 1000000)); +} + +/* + * calculates the speed between points "A" and "B" + * the result comes in meters per second and is always positive + */ + +double +waypt_speed(const waypoint *A, const waypoint *B) +{ + double dist, time; + + dist = radtometers(gcdist( + RAD(A->latitude), RAD(A->longitude), + RAD(B->latitude), RAD(B->longitude))); + if (dist < 0.1) dist = 0; /* calc. diffs on 32- and 64-bit hosts */ + if (dist == 0) return 0; + + time = fabs(waypt_time(A) - waypt_time(B)); + if (time > 0) + return (dist / time); + else + return 0; +} -- 2.30.2